// 淘宝时间戳API
function getTaobaoTimestamp() {
    var response = http.get("http://acs.m.taobao.com/gw/mtop.common.getTimestamp/");
    var data = response.body.json();
    return parseInt(data.data.t); // 返回时间戳
}

// 苏宁时间戳API
function getSuningTimestamp() {
    var response = http.get("http://quan.suning.com/getSysTime.do");
    var data = response.body.json();
    var formattedTime = data.sysTime2.replace(/-/g, "/"); // 格式转换
    return new Date(formattedTime).getTime(); // 返回时间戳
}

// 拼多多时间戳API
function getPinduoduoTimestamp() {
    var response = http.get("http://api.pinduoduo.com/api/server/_stm");
    var data = response.body.json();
    return parseInt(data.server_time); // 返回时间戳
}

// 美团时间戳API
function getMeituanTimestamp() {
    var response = http.get("https://cube.meituan.com/ipromotion/cube/toc/component/base/getServerCurrentTime");
    var data = response.body.json();
    return parseInt(data.data); // 返回时间戳
}

// 小米有品时间戳API
function getXiaomiTimestamp() {
    var response = http.get("https://tptm.hd.mi.com/gettimestamp");
    var rawTime = response.body.string();
    var timeArray = rawTime.split("=");
    return parseInt(timeArray[1]); // 返回时间戳
}

// 国美时间戳API
function getGomeTimestamp() {
    var response = http.get("https://im-platform.gome.com.cn/im-platform/system/serverTime.json?appId=gomeplus_pro");
    var data = response.body.json();
    return parseInt(data.data.time); // 返回时间戳
}

// Vivo商城时间戳API
function getVivoTimestamp() {
    var response = http.get("http://mshopact.vivo.com.cn/tool/config");
    var data = response.body.json();
    return parseInt(data.data.nowTime); // 返回时间戳
}

// 多线程调用时间戳函数
// threads.start(function () {
//     var timestamp = getTaobaoTimestamp();
//     compare(timestamp)
// });

threads.start(function () {
    // var timestamp = getSuningTimestamp();
    // compare(timestamp)
});

threads.start(function () {
    // var timestamp = getPinduoduoTimestamp();
    // compare(timestamp)
});

// threads.start(function () {
//     var timestamp = getMeituanTimestamp();
//     compare(timestamp)
// });

// threads.start(function () {
//     var timestamp = getXiaomiTimestamp();
//     compare(timestamp)
// });

// threads.start(function () {
//     var timestamp = getGomeTimestamp();
//     compare(timestamp)
// });

threads.start(function () {
    var timestamp = getVivoTimestamp();
    compare(timestamp)
});

function compare(timestamp){
    const serverTimestamp = parseInt(timestamp); // 服务器时间戳
    const localTimestamp = Date.now(); // 本地时间戳
    const offset = serverTimestamp - localTimestamp; // 时间偏差

    console.info("服务器时间: " + new Date(serverTimestamp).toLocaleString());
    console.info("本地时间: " + new Date(localTimestamp).toLocaleString());
    console.info("时间偏差: " + offset + " 毫秒");
}



